package com.fileupload.fileupload.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;

import java.util.concurrent.Executor;

@Configuration
public class ThreadPoolConfig {

    @Bean(name = "readExcelTaskExecutor")
    public Executor readExcelTaskExecutor() {
        ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
        executor.setCorePoolSize(5); // 核心线程数
        executor.setMaxPoolSize(10); // 最大线程数
        executor.setQueueCapacity(25); // 队列容量
        executor.setKeepAliveSeconds(120); // 线程空闲时间
        executor.setThreadNamePrefix("ReadExcelExecutor-"); // 线程名前缀
        executor.initialize(); // 初始化线程池
        return executor;
    }

    @Bean(name = "exportExcelTaskExecutor")
    public Executor exportExcelTaskExecutor() {
        ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
        executor.setCorePoolSize(5);
        executor.setMaxPoolSize(10);
        executor.setQueueCapacity(25);
        executor.setKeepAliveSeconds(120);
        executor.setThreadNamePrefix("ExportExcelExecutor-");
        executor.initialize();
        return executor;
    }

}
